package com.cn.design.state.low;

/**
 * @author: zhangyiting
 * @description: 面对对象设计其实就是希望做到代码的责任分解这个类违背了’单一职责原则’。
 * 而且由于’WriteProgram’的方法里面有这么多判断，使得任何需求的改动或增加，都需要更改这个方法。
 * 又违背了’开放－封闭原则’。这类有个解决方案，就是’状态模式’。
 * @createDate: Created in 2022/7/5 23:05
 * @version: 1.0
 */
import lombok.Data;
@Data
public class WorkDemo {
    private int hour;

    private Boolean finish=false;

    public void writeProgram() {
        if (hour < 12) {
            System.err.println("当前时间:上午" + hour + "点");
        } else if (hour < 13) {
            System.err.println("当前时间:中午" + hour + "点");
        } else if (hour < 17) {
            System.err.println("当前时间:下午" + hour + "点");
        } else {
            if (finish) {
                System.err.println("当前时间:下班回家" + hour + "点");
            } else {
                if (hour < 21) {
                    System.err.println("当前时间:加班哦,疲累之极" + hour + "点");
                } else {
                    System.err.println("当前时间:不行了,睡着了" + hour + "点");
                }
            }
        }
    }

    public static void main(String[] args) {
        WorkDemo emergencyProjects = new WorkDemo();
        emergencyProjects.hour = 9;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 10;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 12;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 13;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 14;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 17;
        emergencyProjects.writeProgram();

        emergencyProjects.finish = true;
        //emergencyProjects.finish = false;

        emergencyProjects.writeProgram();
        emergencyProjects.hour = 19;
        emergencyProjects.writeProgram();
        emergencyProjects.hour = 22;
        emergencyProjects.writeProgram();
    }

}
